<template>
	<div>
		<el-input
			style="width: 100%"
			controls-position="right"
			v-if="mode === 'D'"
			:disabled="true"
			:placeholder="!form ? '' : form.placeholder"
		/>
		<el-input
			v-else
			style="width: 100%"
			controls-position="right"
			:precision="form.props.radixNum"
			v-model="form.props.value"
			:disabled="form.perm === 'R'"
			:placeholder="form.placeholder"
		/>
	</div>
</template>
<script lang="ts" setup>
let props = defineProps({
	mode: {
		type: String,
		default: 'D',
	},

	form: {
		type: Object,
		default: () => {},
	},
});

const { proxy } = getCurrentInstance();
import { defineExpose } from 'vue';

const getValidateRule = () => {
	var item = props.form;
	// var itemProps = item.props;

	var checkConfig = (rule: any, value: any, callback: any) => {
		if (item.required) {
			if (!value) {
				return callback(new Error('请填写' + item.name));
			}
		}

    if (!value) {
      return callback(new Error('身份证号不能为空'));
    } else {
      if (!(/^[+]{0,1}(\d+)$|^[+]{0,1}(\d+\.\d+)$/).test(value)) {
        callback(new Error('请输入数字值'))
      } else {
        const reg = /^([1-6][1-9]|50)\d{4}(18|19|20)\d{2}((0[1-9])|10|11|12)(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/
        if (reg.test(value)) {
          callback();
        } else {
          return callback(new Error('请输入正确的身份证号'));
        }
      }
    }

		// if (!value) {
    //   return callback(new Error('手机号不能为空'))}
    // else{
    //     if (!(/^[+]{0,1}(\d+)$|^[+]{0,1}(\d+\.\d+)$/).test(value)) {
    //       callback(new Error('请输入数字值'))
    //     } else {
    //       const reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/
    //       if (reg.test(value)) {
    //         callback();
    //       } else {
    //         return callback(new Error('请输入正确的身份证号'));
    //       }
    //     }
    //   }

		// return callback();
	};
	let ruleArray = [
		{
			validator: checkConfig,
			trigger: 'blur',
		},
	];
	if (item.required) {
		ruleArray.push({ required: true, message: '请填写' + item.name, trigger: 'blur' });
	}
	return ruleArray;
};
defineExpose({ getValidateRule });
</script>
